package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Workorders;
import com.ruoyi.system.service.IWorkordersService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工单记录，用于跟踪故障的维修工作进度Controller
 * 
 * @author ruoyi
 * @date 2024-04-23
 */
@RestController
@RequestMapping("/system/workorders")
public class WorkordersController extends BaseController
{
    @Autowired
    private IWorkordersService workordersService;

    /**
     * 查询工单记录，用于跟踪故障的维修工作进度列表
     */
    @PreAuthorize("@ss.hasPermi('system:workorders:list')")
    @GetMapping("/list")
    public TableDataInfo list(Workorders workorders)
    {
        startPage();
        List<Workorders> list = workordersService.selectWorkordersList(workorders);
        return getDataTable(list);
    }

    /**
     * 导出工单记录，用于跟踪故障的维修工作进度列表
     */
    @PreAuthorize("@ss.hasPermi('system:workorders:export')")
    @Log(title = "工单记录，用于跟踪故障的维修工作进度", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Workorders workorders)
    {
        List<Workorders> list = workordersService.selectWorkordersList(workorders);
        ExcelUtil<Workorders> util = new ExcelUtil<Workorders>(Workorders.class);
        util.exportExcel(response, list, "工单记录，用于跟踪故障的维修工作进度数据");
    }

    /**
     * 获取工单记录，用于跟踪故障的维修工作进度详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:workorders:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(workordersService.selectWorkordersById(id));
    }

    /**
     * 新增工单记录，用于跟踪故障的维修工作进度
     */
    @PreAuthorize("@ss.hasPermi('system:workorders:add')")
    @Log(title = "工单记录，用于跟踪故障的维修工作进度", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Workorders workorders)
    {
        return toAjax(workordersService.insertWorkorders(workorders));
    }

    /**
     * 修改工单记录，用于跟踪故障的维修工作进度
     */
    @PreAuthorize("@ss.hasPermi('system:workorders:edit')")
    @Log(title = "工单记录，用于跟踪故障的维修工作进度", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Workorders workorders)
    {
        return toAjax(workordersService.updateWorkorders(workorders));
    }

    /**
     * 删除工单记录，用于跟踪故障的维修工作进度
     */
    @PreAuthorize("@ss.hasPermi('system:workorders:remove')")
    @Log(title = "工单记录，用于跟踪故障的维修工作进度", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(workordersService.deleteWorkordersByIds(ids));
    }
}
